package com.mcxx.modules.miniSalvation.family.service.read;

import com.mcxx.common.exception.BizException;
import com.mcxx.modules.miniSalvation.check.dto.CheckMemberDTO;
import com.mcxx.modules.miniSalvation.check.dto.IntegrateCheckMemberDTO;
import com.mcxx.modules.miniSalvation.family.dao.read.FamilySupportReadDAO;
import com.mcxx.modules.miniSalvation.family.entity.FamilySupportEntity;
import com.mcxx.util.FailureCode;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
@TaTransactional(readOnly = true)
public class FamilySupportReadService {
    @Autowired
    private FamilySupportReadDAO familySupportReadDAO;


    public List<FamilySupportEntity> getFamilySupportList(String familyId) {
        return familySupportReadDAO.queryFamilySupportByFamilyId(familyId);
    }


    public FamilySupportEntity getFamilySupportById(String id) {
        return familySupportReadDAO.queryFamilySupportById(id);
    }


    public void verifyIdcardInFamily(String familyId, String idcard, String supportId) {
        String existedId = familySupportReadDAO.getIdByInFamily(familyId,idcard, supportId);
        if (StringUtils.isNotEmpty(existedId)) {
            throw new BizException(FailureCode.ERR_10050);
        }
    }

    public void verifyIdcardInFamilyCount(String familyId, String idcard, String memberId) {
        int count = familySupportReadDAO.IdcardInFamilyCount(familyId,idcard, memberId);
        if (count > 0) {
            throw new BizException("-1","同一个家庭成员不能被同一个身份证号多次录入");
        }
    }


    public int cntInSupport(String familyId, String idcard) {
        return familySupportReadDAO.cntInSupport(familyId,idcard);
    }

    public List<CheckMemberDTO> selectSupportListInfo(String familyId){
        return familySupportReadDAO.selectSupportListInfo(familyId);
    }

    public List<Map<String,Object>> selectSupportToCalculate(String familyId){
        return familySupportReadDAO.selectSupportToCalculate(familyId);
    }

    public List<Map<String,Object>> selectLowerSupportToCalculate(String familyId){
        return familySupportReadDAO.selectLowerSupportToCalculate(familyId);
    }

    public List<IntegrateCheckMemberDTO> seletcSupportForIntegrate(String orderId,String familyId){
        return familySupportReadDAO.seletcSupportForIntegrate(orderId,familyId);
    }
}
